package com.zzyl.controller;


import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("IOT设备管理")
@RestController
@RequestMapping("/iot")
public class DeviceController extends BaseController {

    @Autowired
    private DeviceService deviceService;

    @ApiOperation("从物联网平台同步产品列表")
    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    public ResponseResult allProduct(){
        List<ProductVo> allProduct = deviceService.getAllProduct();
        return success(allProduct);
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return success();
    }


    @GetMapping("/pageQueryDevice")
    public ResponseResult pageQueryDevice(DevicePageQueryDto dto){
       PageResponse page=  deviceService.getByPage(dto);
       return success(page);
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult QueryDeviceDetail(@RequestBody QueryDeviceDetailRequest dto){
        DeviceVo deviceVo =deviceService.queryDeviceDetail(dto);
        return success(deviceVo);
    }

    @PostMapping("/QueryThingModelPublished")
    public ResponseResult QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest dto){

        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData resout =deviceService.queryThingModelPublished(dto);
        return success(resout);
    }


    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest dto){

        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData resout =deviceService.queryDevicePropertyStatus(dto);
        return success(resout);
    }

    @PostMapping("/UpdateDevice")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return success();
    }
}
